package com.yuzhi.common.enums;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.EnumUtil;
import io.vavr.control.Option;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;

/**
 * @ClassName: AlarmTypeEnum
 * @Author: Mario
 * @Description: 告警类型
 */
@Getter
@AllArgsConstructor
public enum AlarmTypeEnum {
    /**
     * 雨量测点
     */
    RAIN_FALL("雨量测点", "2"),

    /**
     * 水位测点
     */
    WATER_LEVEL("水位测点", "7"),

    /**
     * 墒情测点
     */
    SOIL_MOISTURE("墒情测点", "5");

    private final String typeName;

    private final String typeValue;

    public static Map<String, String> toMap() {
        Map<String, AlarmTypeEnum> enumMap = EnumUtil.getEnumMap(AlarmTypeEnum.class);
        Map<String, String> resultMap = MapUtil.newHashMap(enumMap.size());
        for (AlarmTypeEnum alarmType : enumMap.values()) {
            resultMap.put(alarmType.getTypeValue(), alarmType.getTypeName());
        }
        return resultMap;
    }

    public static String getNameByValue(String typeValue) {
        return Option.when(CharSequenceUtil.isNotBlank(typeValue), () -> toMap().getOrDefault(typeValue, CharSequenceUtil.EMPTY)).getOrElse(CharSequenceUtil.EMPTY);
    }
}
